<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/7/26
 * Time: 9:44
 */

namespace Admin\Controller;

use Think\Controller;
use Think\Page;
class SearchController extends CommonController
{
    //搜索
    public function search()
    {
        $param=null;
        $select = $_POST['select'];
        $keyword = $_POST['keyword'];
        $select_txt = $_POST['select_name'];

        $Data=M("loanborrower");
        import('ORG.Util.Page');// 导入分页类
        $count = $Data->where( $param)->count();// 查询满足要求的总记录数 $map表示查询条件
        $Page = new \Think\Page($count,20);// 实例化分页类 传入总记录数

        foreach($param as $key=>$val) {
            $Page->parameter  .=  "$key=".urlencode($val)."&";
        }

        $show = $Page->show();// 分页显示输出
        $search = M("loanborrower")->where("{$select} like '%{$keyword}%'")->limit($Page->firstRow.','.$Page->listRows)->select();
        $count = M("loanborrower")->where("{$select} like '%{$keyword}%'")->limit($Page->firstRow.','.$Page->listRows)->count();
        $countMoney = M("loanborrower")->where("{$select} like '%{$keyword}%'")->limit($Page->firstRow.','.$Page->listRows)->sum("borrow_money");

        $this->assign("select_txt",$select_txt);
        $this->assign("keyword",$keyword);
        $this->assign("countMoney",$countMoney);
        $this->assign("count",$count);
        $this->assign("search",$search);// 赋值数据集
        $this->assign("page",$show);    //赋值分页输出
        $this->assign("param",$param);  // 赋值分页输出

        $this->display("index");
    }



    public function index()
    {
        $this->display("index");
    }

}